import 'dart:convert';

class TagItem {
  String? id;
  String? content;
  String? cover;
  String? userId;
  String? categoryId;
  String? categoryName;
  String? categoryPid;
  String? categoryPName;
  String? otherUserId;
  String? album;
  String? albumName;
  int? imgCount;
  int? status;
  String? avatar;
  String? username;
  String? imgsUrl;
  int? count;
  List<Tag>? tagList;
  String? viewCount;
  String? agreeCount;
  String? collectionCount;
  String? commentCount;
  String? time;

  TagItem({
    required this.id,
    required this.content,
    required this.cover,
    required this.userId,
    required this.categoryId,
    this.categoryName,
    this.categoryPid,
    this.categoryPName,
    this.otherUserId,
    this.album,
    this.albumName,
    this.imgCount,
    required this.status,
    required this.avatar,
    required this.username,
    this.imgsUrl,
    required this.count,
    this.tagList,
    required this.viewCount,
    required this.agreeCount,
    required this.collectionCount,
    required this.commentCount,
    this.time,
  });

  factory TagItem.fromJson(Map<String, dynamic> json) {
    return TagItem(
      id: json['id'],
      content: json['content'],
      cover: json['cover'],
      userId: json['userId'],
      categoryId: json['categoryId'],
      categoryName: json['categoryName'],
      categoryPid: json['categoryPid'],
      categoryPName: json['categoryPName'],
      otherUserId: json['otherUserId'],
      album: json['album'],
      albumName: json['albumName'],
      imgCount: json['imgCount'],
      status: json['status'],
      avatar: json['avatar'],
      username: json['username'],
      imgsUrl: json['imgsUrl'],
      count: json['count'],
      tagList: json['tagList'] != null ? List<Tag>.from(json['tagList'].map((x) => Tag.fromJson(x))) : null,
      viewCount: json['viewCount'],
      agreeCount: json['agreeCount'],
      collectionCount: json['collectionCount'],
      commentCount: json['commentCount'],
      time: json['time'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'content': content,
      'cover': cover,
      'userId': userId,
      'categoryId': categoryId,
      'categoryName': categoryName,
      'categoryPid': categoryPid,
      'categoryPName': categoryPName,
      'otherUserId': otherUserId,
      'album': album,
      'albumName': albumName,
      'imgCount': imgCount,
      'status': status,
      'avatar': avatar,
      'username': username,
      'imgsUrl': imgsUrl,
      'count': count,
      'tagList': tagList != null ? List<dynamic>.from(tagList!.map((x) => x.toJson())) : null,
      'viewCount': viewCount,
      'agreeCount': agreeCount,
      'collectionCount': collectionCount,
      'commentCount': commentCount,
      'time': time,
    };
  }
}

class Tag {
  String id;
  String name;

  Tag({
    required this.id,
    required this.name,
  });

  factory Tag.fromJson(Map<String, dynamic> json) {
    return Tag(
      id: json['id'],
      name: json['name'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'name': name,
    };
  }
}

class TagItemList {
  List<TagItem> items;

  TagItemList({required this.items});

  factory TagItemList.fromJson(List<dynamic> json) {
    return TagItemList(
      items: List<TagItem>.from(json.map((x) => TagItem.fromJson(x))),
    );
  }

  List<dynamic> toJson() {
    return List<dynamic>.from(items.map((x) => x.toJson()));
  }
}
